package com.pakazaka.simplecrawler;

import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Arrays;
import static java.util.Arrays.asList;

/**
 *
 * @author Remi
 */
public abstract class Window {

    protected static boolean dragged = false;
    protected int x, y, height, width, ofx, ofy, priority;
    protected String caption = "null";
    protected boolean dragging = false;

    public Window(int width, int height, int x, int y, int priority, String caption) {
        this.x = width;
        this.height = height;
        this.width = width;
        this.x = x;
        this.y = y;
        this.caption = caption;
        this.priority = priority;
    }

    public abstract void paint(Graphics g, Object obj);

    public abstract int getWidth();

    public abstract int getHeight();

    public abstract int getX();

    public abstract int getY();

    public int getPriority() {
        return priority;
    }

    public static String[] getWrappedString(String text, int width) {
        StringBuilder sb = new StringBuilder(text);
        ArrayList<String> result = new ArrayList<>();

        int i = 0;
        while (i + width < sb.length() && (i = sb.lastIndexOf(" ", i + width)) != -1) {
            sb.replace(i, i + 1, "\r\n");
        }

        String[] strings = sb.toString().split("\r\n");
        result.addAll(asList(strings));

        return strings;
    }
}
